/** @file r_view.cpp
    @brief Camera view */

#include "render/r_view.h"

using namespace G3;

//==============================================================================
// Multiplies OpenGL matrix by our camera rotation matrix
//==============================================================================
void G3::VIEW::glMultRotationMatrix () {
    MATRIX4x4F M = Rotation.GetMatrix ();
    glMultMatrixf (M.m);
}

//==============================================================================
// Multiplies OpenGL matrix by our camera matrix
//==============================================================================
void G3::VIEW::glLook () {
    glMultRotationMatrix ();
    glTranslatef (-Position.x, -Position.y, -Position.z);

    ViewFrustum.glExtract ();
	ViewFrustum.UpdateOrientation (GetWorldPosition (), GetUpVector (), -GetForwardVector (), -GetRightVector ());
}

//==============================================================================
// Sets ViewFrustum FieldOfView
//==============================================================================
void G3::VIEW::SetFieldOfView (float FOV) {
	ViewFrustum.FieldOfView = FOV;
}

//==============================================================================
// Sets ViewFrustum AspectRatio
//==============================================================================
void G3::VIEW::SetAspectRatio (uint Width, uint Height) {
	float w = Width, h = Height;
	ViewFrustum.AspectRatio = w / h;
}

//==============================================================================
// Sets ViewFrustum Near and Far plane distances from the frustum origin
//==============================================================================
void G3::VIEW::SetNearFarDistance (float NearDist, float FarDist) {
	ViewFrustum.NearPlane = NearDist;
	ViewFrustum.FarPlane = FarDist;
}
